<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
    	$this->verify_login();
    	$banner=M('banner');
    	$bannerList=$banner->order("sort desc")->select();
    	$this->assign("bannerList",$bannerList);
        $this->display();
    }
    public function upload_banner(){
    	$upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     2097152 ;// 设置附件上传大小
	    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	    $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
	    $upload->savePath  =      'banner/';
	    $upload->autoSub = false;
	    // 上传单个文件 
	    $info   =   $upload->uploadOne($_FILES['imgurl']);
	    if(!$info) {// 上传错误提示错误信息
	        $this->error($upload->getError());
	    }else{// 上传成功 获取上传文件信息
	        $data['imgurl']='Uploads/'.$info['savepath'].$info['savename'];
	        $data['sort']=I('post.sort');
	        $banner=M('banner');
	        if($banner->add($data)){
	        	$this->success("保存成功",U('index/index'));
	        }else{
	        	$this->error("保存失败");
	        }

	    }
    }
    public function del(){
    	$id=I('get.id');
    	$banner=M('banner');
    	$res=$banner->where('id='.$id)->delete();
    	if($res){
        	$this->success("删除成功",U('index/index'));
        }else{
        	$this->error("删除失败");
        }
    }
}